Skip to content

Expo support upgrade#478

Merged
vladimir-kotikov merged 6 commits into
microsoft:masterfrom
itoys:expo-support-upgrade
Jul 26, 2017
Merged

Expo support upgrade#478
vladimir-kotikov merged 6 commits into
microsoft:masterfrom
itoys:expo-support-upgrade

Conversation

@itoys

@itoys itoys commented Jul 18, 2017

Copy link
Copy Markdown
Contributor

@msftclas

Copy link
Copy Markdown

@itoys,
Thanks for your contribution as a Microsoft full-time employee or intern. You do not need to sign a CLA.
Thanks,
Microsoft Pull Request Bot

@itoys itoys force-pushed the expo-support-upgrade branch from 4c58811 to 4f7b30b Compare July 19, 2017 12:06
Comment thread src/common/commandExecutor.ts Outdated
const reactCommand = HostPlatform.getNpmCliCommand(CommandExecutor.ReactNativeCommand);
return this.spawnChildProcess(reactCommand, this.combineArguments(command, args), options);
const reactCommand = CommandExecutor.ReactNativeCLI;
return this.spawnChildProcess("node", [reactCommand, command, ...args], options);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itoys is it really required to spawn cli.js directly rather than via react-native-cli?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly like exp run builder

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packager, you meant. Anyway, this call is effectively has the same result as this.spawnChildProcess(reactCommand, this.combineArguments(command, args), options) so I wonder if the change was really required.

return Q.reject<void>(ErrorHelper.getNestedError(reason, InternalErrorCode.CommandFailed, command));
}

private combineArguments(firstArgument: string, otherArguments: string[] = []) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread src/common/packager.ts Outdated
return this.monkeyPatchOpnForRNPackager()
.then(() => {
let args = ["--port", port.toString()];
let args: any = ["--port", port.toString()];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any -> string[]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it can contain arrays
See

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't contain anything other than strings - semantically args is an array of parameters passed to the packages and commandline parameters are always strings.

The line that you pointing me to (args.push("--assetExts", ["ttf"])) is also very confusing and probably would look better if rewritten to args.push("--assetExts", ["ttf"].toString())

Another argument is that I perfectly remember that you've had a lot of troubles you could avoid if array value was converted to string explicitly

@itoys itoys Jul 25, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

child_process.spawn is flatted nested arrays, we can get array from app.json or exp.json
Otherwise we should check typeof value and join it (Array.prototype.join)


declare class ExpConfig {
public name: string;
public slug: string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are name and slug required? IIRC CRNA app doesn't have them defined in package.json

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See Expo docs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, makes sense

Comment thread src/common/exponent/xdlInterface.ts Outdated
let commandExecutor = new CommandExecutor();
xdlPackage = commandExecutor.spawnWithProgress(HostPlatform.getNpmCliCommand("npm"),
["install", `xdl@${XDL_VERSION}`, "--verbose"],
["install", EXPO_DEPS.join(", "), "--verbose"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use , to join CLI arguments. The common practice is to delimit using just space

Comment thread src/common/packager.ts Outdated
})
args.push("--root", path.resolve(this.projectPath + "/.vscode/"));

let helper = new ExponentHelper(this.projectPath);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these two lines please see my comment to rn-extension.ts and #359

*/
private pathToFileInWorkspace(filename: string): string {
return path.join(this.projectRootPath, filename);
return path.join(this.projectRootPath, filename).replace(DBL_SLASHES, "/");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use string replace to normalize paths. Use path.posix.join instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace is faster than split + path.posix.join, and with leading slash

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, It appears that path.join would not correct path separators.

Comment thread src/common/exponent/exponentHelper.ts Outdated
// Not in a react-native project
return false;
});
private getFromExpConfig<T>(key: string): Q.Promise<T> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why is it really required to use generics? Semantically I'd rather return any and then cast result to expected type

private detectEntry(): Q.Promise<string> {
this.lazilyInitialize();
return Q.all([
this.fs.exists(this.pathToFileInWorkspace(DEFAULT_EXPONENT_INDEX)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking some predefined "magic" locations you might want to look at "main" entry in package.json. I ddn't find any documentation but from my experience it always points to the main entry point. Also note the case when for example "main" points to non-existent file - in that case you'll need to check for ios and adroid variants of that file, i.e.

index.js (doesn't exist) -> index.ios.js / index.android.js

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a bit refactoring for legacy code. And we discussed about that.

const expJsonPath = this.pathToFileInWorkspace(EXP_JSON);
if (!this.fileSystem.existsSync(expJsonPath) || exponentJson.overwriteExpJson) {
private patchAppJson(isExpo: boolean = true): Q.Promise<void> {
return this.readAppJson()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find .catch for this. What happens if neither app.json nor exp.json exists

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's incorrect app, and we'll crash, i think it's ok

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see at least one code path where the exception here will not be caught by caller code which likely would lead to extension crash - this is a bad UX and must be avoided if possible.

Have you tested this scenario?

@vladimir-kotikov vladimir-kotikov merged commit 94cd514 into microsoft:master Jul 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants